Devices > Import/Export Devices > Sonic Queue EIE (SonicQ) > Scripting

Sonic Queue (SonicQ) Scripting

CygNet utilizes Sonic's COM functions to communicate with their queue objects. Full communication in script with a queue has four separate steps: connection, receiving, sending, and browsing.

Important: To allow the following scripts to be run successfully, a SonicQ broker must be online and configured according to Sonic's recommendations.

Scripting Options

CygNet communicates with the SonicQ Broker with the following scripting options: Connection, Receiving, Sending, and Browsing.

Connection

To send, receive, or browse a queue, first the script must establish a connection. Establishing a connection is the most complicated process in Sonic's COM library. It requires the use of four separate objects: Factories, Connections, Sessions, and Queues.

Factory - A Factory is the object that creates and establishes communication with the queue. Once established it creates the Connection object. The Factory must be given the URL of the queue, as well as the user name and password required for security.

Example

Dim factory

Set factory = CreateObject("JMSCOMClient.JMSQueueConnectionFactory")

Call factory.initialize5(browserURL, username, password)

Connection - A Connection is the object created by a Factory that creates Sessions with a queue. Only a single Factory is needed to create many Connections to a queue.

Example

Dim connection

Set connection = factory.createQueueConnection

connection.start

Session - A Session is created by a Connection and serves as the means for sending and receiving messages from the queue. It also creates a Queue object, which specifies the queue to communicate with during sending and receiving.

Example

Dim session

Dim queue

Set session = connection.createQueueSession(False, 1)

Set queue = session.createQueue(queueName)

With a Session and a Queue, the script can create the objects necessary for sending, receiving, and browsing.

Back to top

Receiving

To receive a message off a Sonic queue, first the script must create a Receiver. This requires a Session and Queue object.

Example

Dim receiver

Set receiver = session.createReceiver(queue)

Now, the receiver may be set up to read messages off the queue defined for the session.

Example

Dim message

Set message = m_receiver.receive

message.acknowledge

In the above example, the variable 'message' will have the contents of the first message off of the queue.

Back to top

Sending

To send or write a message off to a Sonic queue, first the script must create a Sender. This requires a Session and Queue object.

Example

Dim sender

Set sender = session.createSender(queue)

Now, the receiver may be set up to write messages to the queue defined for the session.

Example

Dim message

message.setText msgText

Call sender.send(m_message)

In the above example, the contents of the variable 'msgText' have been written to the queue.

Back to top

Browsing

Receiving a message requires the receiver to ask if a message is available, that is, if the queue has a message in it. If the queue is empty, a receive operation with return nothing. Browsing will wait for a message to be put on the queue and return it as soon as it is available.

To browse a Sonic queue, first the script must create a Browser, which creates a Browser Enumeration. This requires a Session and Queue object.

Example

Dim browser

Dim browserEnum

Set browser = session.createBrowser(queue)

Set browserEnum = browser.getEnumeration

To check if a queue has any messages, call the following function of the Browser Enumeration:

browseEnum.hasMoreElements

To read the next message on the queue, you ask for the variable 'next element.'

Example

Dim message

Set message = browserEnum.nextElement

In the above example, 'message' has the contents of the next message off the queue.

Back to top

Let us know how we can improve this topic.

CygNet at weatherford.com

© 2020 Weatherford. All rights reserved.